/**
 * 时间对象的格式化;
 */
Date.prototype.format = function(format) {
	/*
	 * eg:format="yyyy-MM-dd hh:mm:ss";
	 */
	var o = {
		"M+" : this.getMonth() + 1, // month
		"d+" : this.getDate(), // day
		"h+" : this.getHours(), // hour
		"m+" : this.getMinutes(), // minute
		"s+" : this.getSeconds(), // second
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		"S" : this.getMilliseconds()
		// millisecond
	}

	if (/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
						- RegExp.$1.length));
	}

	for (var k in o) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1
							? o[k]
							: ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
}

Date.prototype.addMonth = function (num) {
	var dt = new Date(this);
	dt.setMonth(dt.getMonth() + num);
    return dt;
}

String.prototype.addMonth = function (num) {
    var aYmd = this.split('-');
    var dt = new Date(aYmd[0], aYmd[1], aYmd[2]);
    
    dt.setMonth(dt.getMonth() + num);
    
    var y = dt.getFullYear();
    var m = dt.getMonth();
    var d = dt.getDate();
    //坑爹啊，月份是从0开始啊！！！！
    if (m == 0) { m = 12; y = y - 1; }

    if (m < 10) m = '0' + m;
    if (d < 10) d = '0' + d;
    return y + '-' + m + '-' + d;
}

String.prototype.addDays = function (days) {
    var aYmd = this.split('-');
    var dt = new Date(aYmd[0], aYmd[1], aYmd[2]);
    
    dt.setDate(dt.getDate() + days);
    
    var y = dt.getFullYear();
    var m = dt.getMonth();
    var d = dt.getDate();
    //坑爹啊，月份是从0开始啊！！！！
    if (m == 0) { m = 12; y = y - 1; }

    if (m < 10) m = '0' + m;
    if (d < 10) d = '0' + d;
    return y + '-' + m + '-' + d;
}

String.prototype.toDate = function () {
    var aYmd = this.split('-');
    var dt = new Date(aYmd[0], aYmd[1]-1, aYmd[2]);
	return dt;
}

String.prototype.formatDate = function (format) {
    var dt = this.toDate();
    return dt.format(format);
}